<!DOCTYPE html>
<html xmlns:scrollbar="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>积分转换比例规则</title>
    <meta name="keywords" content="积分转换比例规则"/>
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
</head>

<style>


    .mall_box_item {

        display: flex;
    }

    .list_top {

        display: flex;
        width: 150px;
        margin-top: 10px;
        padding-left: 30px;


    }

    .list_top_item {
        padding-top: 20px;
        flex: 1;

    }

    .proportionUpate {
        padding-top: 30px;
        margin-left: 100px;
        display: flex;
    }

</style>

<body>
<!--弹出层一级开始-->
<div class="layui-tab">
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table id="plan" lay-filter="plan"></table>
        </div>
    </div>
</div>
<!--弹出层一级结束-->
<div id="insert_member_proportion" style="display: none" scrollbar="false">
    <label>释放倍数:</label>
    <div class="layui-input-inline">
        <input type="text" id="multi_incremetn1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>积分兑换金币比例:</label>
    <div class="layui-input-inline">
        <input type="text" id="integral_exchange_coin_proportion1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>积分兑换产品:</label>
    <div class="layui-input-inline">
        <input type="text" id="integral_exchange_product_proportion1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>手续费:</label>
    <div class="layui-input-inline">
        <input type="text" id="coin_exchange_money_proportion1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>等级:</label>
    <div class="layui-input-inline">
        <input type="text" id="level1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>准备金比例:</label>
    <div class="layui-input-inline">
        <input type="text" id="reserve_proportion1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>积分兑换率:</label>
    <div class="layui-input-inline">
        <input type="text" id="integral_exchange_coin_rate1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>成为会员标准:</label>
    <div class="layui-input-inline">
        <input type="text" id="standard1" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <div id="verfiyProportion" class=" list_top_item"></div>
</div>


<div id="proportionUpate" class="layui-input-block" style="display:none">
    <label>释放倍数:</label>
    <div class="layui-input-inline">
        <input type="text" id="multi_incremetn" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>积分兑换金币比例:</label>
    <div class="layui-input-inline">
        <input type="text" id="integral_exchange_coin_proportion" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>积分兑换产品:</label>
    <div class="layui-input-inline">
        <input type="text" id="integral_exchange_product_proportion" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>手续费:</label>
    <div class="layui-input-inline">
        <input type="text" id="coin_exchange_money_proportion" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>准备金比例:</label>
    <div class="layui-input-inline">
        <input type="text" id="reserve_proportion" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>积分兑换率:</label>
    <div class="layui-input-inline">
        <input type="text" id="integral_exchange_coin_rate" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
    <label>成为会员标准:</label>
    <div class="layui-input-inline">
        <input type="text" id="standard" class="layui-input"
               placeholder="" autocomplete="off"/>
    </div>
</div>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getInsert">新增</button>
        <!--<button class="layui-btn layui-btn-sm" data-type="getCheckData" lay-event="getDelete">删除</button>-->
    </div>
</script>
<!--弹出层二级结束-->
</body>

<script type="text/html" id="barDemo">
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" language="JavaScript" src="/static/layui/layui.js"></script>

<script>
    $(function () {
        layui.use('element', function () {
            var element = layui.element;
        });

        layui.use(['table', 'layer'], function () {
            var table = layui.table;
            var layer = layui.layer;
            table.render({
                elem: '#plan'
                , height: 312
                , url: '/system/activity/generalIntegral/getMemberRule' //数据接口
                , page: true //开启分页
                , cols: [[ //表头
                    {type: 'checkbox', LAY_CHECKED: false, filter: 'test'}
                    , {field: 'id', title: 'ID', sort: true}
                    , {field: 'standard', title: '成为会员标准', sort: true}
                    , {field: 'level', title: '级别'}
                    , {field: 'integral_exchange_coin_proportion', title: '兑货卷和金币汇率'}
                    , {field: 'integral_exchange_product_proportion', title: '兑货卷和提货卷汇率'}
                    , {field: 'coin_exchange_money_proportion', title: '手续费'}
                    , {field: 'reserve_proportion', title: '准备金比例'}
                    , {field: 'integral_exchange_coin_rate', title: '积分兑换率'}
                    , {field: 'multi_incremetn', title: '放大比例', sort: true, totalRow: true}
                    , {fixed: 'right', width: 165, align: 'center', toolbar: '#barDemo'}
                ]]
                , id: 'userTableReload'
                , toolbar: '#toolbarDemo'
            });
            $(".layui-tab").css("margin", "0");
            $(".layui-tab-content").css("padding", "0");
            $(".layui-form.layui-border-box.layui-table-view").css("margin", "0");
            $("#level").blur(function () {
                var val = $("#level").val();
                val = val.trim();
                if (val != null && "" != val) {
                    $.ajax({
                        type: "get",
                        url: "/system/activity/generalIntegral/checkDuplicateLevelExists",
                        data: {"level": val},
                        success: function (data) {
                            if (data.state == false) {
                                // alert(data.msg);
                                $("#verifyLevel").css("display", "inline-block");
                                $("#verifyLevel").html(data.msg);
                                $("#verifyLevel").css("color", "red");
                                return false;
                            }else{
                                $("#verifyLevel").html("");

                            }
                        },
                    })
                }
            });


            table.on('toolbar(plan)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id),
                    data = checkStatus.data; //获取选中的数据
                switch (obj.event) {
                    case "getInsert":
                        layer.open({
                            type: 1,//类型
                            id: "insertTab",
                            area: ['600px', '300px'],//定义宽和高
                            title: '增加购买获赠积分规则',//题目
                            shadeClose: false,//点击遮罩层关闭
                            btn: ['确认', '取消'],
                            content: $("#insert_member_proportion") //注意，如果str是object，那么需要字符拼接。
                            , yes: function (index, layero) {
                                var multi_incremetn = $("#multi_incremetn1").val();
                                var integral_exchange_coin_proportion = $("#integral_exchange_coin_proportion1").val();
                                var integral_exchange_product_proportion = $("#integral_exchange_product_proportion1").val();
                                var coin_exchange_money_proportion = $("#coin_exchange_money_proportion1").val();
                                var reserve_proportion = $("#reserve_proportion1").val();
                                var integral_exchange_coin_rate = $("#integral_exchange_coin_rate1").val();
                                var standard = $("#standard1").val();
                                var level = $("#level1").val();
                                $.ajax({
                                    url: "/system/activity/generalIntegral/insertMemberRule",
                                    type: "get",
                                    data: {multi_incremetn: multi_incremetn,
                                        integral_exchange_coin_proportion: integral_exchange_coin_proportion,
                                        integral_exchange_product_proportion: integral_exchange_product_proportion,
                                        coin_exchange_money_proportion: coin_exchange_money_proportion,
                                        reserve_proportion: reserve_proportion,
                                        integral_exchange_coin_rate: integral_exchange_coin_rate,
                                        standard: standard,
                                        level:level,
                                    },
                                    success: function (data) {
                                        layer.msg(data.msg, {
                                                time: 600
                                            }
                                            , function () {
                                                //执行重载
                                                table.reload('userTableReload', {
                                                    page: {
                                                        curr: 1 //重新从第 1 页开始
                                                    }
                                                });
                                                layer.close(index1);
                                            });
                                    },
                                    //未执行
                                    fail: function (data) {
                                    }
                                })
                            }
                        });
                        break;
                    case "getDelete":
                        getCheckData();
                    function getCheckData() { //获取选中数据
                        var delList = new Array();

                        for (var i = 0; i < data.length; i++) {
                            delList.push(data[i].id);
                        }
                        if (delList.length == 0) {
                            layer.msg("请勾选后再删除!");
                            return false;
                        }
                        var strify = delList;
                        console.log(strify);
                        $.ajax({
                            url: "/system/activity/generalIntegral/deleteInviteeRule",
                            type: 'get',
                            dataType: 'json',
                            data: {
                                id: strify
                            },
                            success: function (data) {
                                if (data == 0) {
                                    layer.msg('删除失败！', {icon: 5, offset: "auto", time: 2000});//提示框
                                } else {
                                    layer.msg('删除成功！', {icon: 6, offset: "auto", time: 2000});//提示框
                                }

                                setTimeout(function () {
                                    location.reload();//重新加载页面表格
                                }, 2100);
                            }
                        })
                    }

                        break;
                    default:
                        break;
                }
                ;

            })
            ;
            // 监听工具条
            table.on('tool(plan)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                var layer = layui.layer, $ = layui.$;
                var form = layui.form;
                if (layEvent === 'detail') { //查看
                    window.open('/system/activity/generalIntegral?id=' + data.id);
                } else if (layEvent === 'del') { //删除
                    layer.confirm('是否确认删除？', function (index) {
                        obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        layer.close(index);
                        //向服务端发送删除指令
                        var delList = new Array();
                        delList.push(data.id);
                        $.post("/system/activity/generalIntegral/deleteInviteeRule", {
                                id: delList
                            },
                            function (data) {
                                if (data.code == 0) {
                                    alert("删除成功");
                                } else {
                                    alert("删除失败");
                                }
                            });

                    });
                } else if (layEvent === 'edit') {

                    // var checkStatus = table.checkStatus('id');
                    var id = data.id;
                    let standard= data.standard;
                    let integral_exchange_coin_proportion= data.integral_exchange_coin_proportion;
                    let integral_exchange_product_proportion= data.integral_exchange_product_proportion;
                    let coin_exchange_money_proportion= data.coin_exchange_money_proportion;
                    let reserve_proportion= data.reserve_proportion;
                    let integral_exchange_coin_rate= data.integral_exchange_coin_rate;
                    let proportion = data.multi_incremetn;
                    $("#multi_incremetn").val(proportion);
                    $("#integral_exchange_coin_proportion").val(integral_exchange_coin_proportion);
                    $("#integral_exchange_product_proportion").val(integral_exchange_product_proportion);
                    $("#coin_exchange_money_proportion").val(coin_exchange_money_proportion);
                    $("#reserve_proportion").val(reserve_proportion);
                    $("#integral_exchange_coin_rate").val(integral_exchange_coin_rate);
                    $("#standard").val(standard);
                    layer.open({
                        type: 1,
                        title: "释放倍数",
                        area: ['1700px', '300px'],
                        btn: ["确定", "取消"],
                        content: $("#proportionUpate"),
                        yes: function (index, layero) { // 确认按钮回调函数
                            // 监听提交按钮
                            let iframeIndex = layer.index;
                            var multi_incremetn = $("#multi_incremetn").val();
                            var integral_exchange_coin_proportion = $("#integral_exchange_coin_proportion").val();
                            var integral_exchange_product_proportion = $("#integral_exchange_product_proportion").val();
                            var coin_exchange_money_proportion = $("#coin_exchange_money_proportion").val();
                            var reserve_proportion = $("#reserve_proportion").val();
                            var integral_exchange_coin_rate = $("#integral_exchange_coin_rate").val();
                            var standard = $("#standard").val();
                            $.ajax({
                                type: "get",
                                url: "/system/activity/generalIntegral/updateMemberLevel",
                                data: {
                                      multi_incremetn: multi_incremetn
                                    , integral_exchange_product_proportion: integral_exchange_product_proportion
                                    , integral_exchange_coin_proportion: integral_exchange_coin_proportion
                                    , coin_exchange_money_proportion: coin_exchange_money_proportion
                                    , reserve_proportion: reserve_proportion
                                    , integral_exchange_coin_rate: integral_exchange_coin_rate
                                    , "id": id
                                    , standard:standard
                                },
                                dataType: "json",
                                success: function () {
                                    layer.close(iframeIndex);
                                    data.msg, {
                                        time: 600
                                    }, function () {
                                        //执行重载
                                        table.reload('userTableReload', {
                                            page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        });
                                        layer.close(iframeIndex);
                                    }
                                    // alert("修改成功");
                                }
                            })
                        },
                     });
                }
            });


        })
        ;
    })
    ;

    function deleteInviteeRule() {
        layer.confirm('是否确认删除？', function (index) {
            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
            layer.close(index);
            //向服务端发送删除指令
            $.post("/system/activity/generalIntegral/deleteInviteeRule", {
                    id: data.id
                },
                function (data) {
                    if (data.code == 0) {
                        alert("删除成功");
                    } else {
                        alert("删除失败");
                    }
                });
        });
    }
</script>
<script type="text/html" id="delete">
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看方案</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</html>
